package Sql;

import Model.Buku;
import Model.Perpustakaan;
import Model.Publikasi;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import oracle.jdbc.pool.OracleDataSource;

public class TestPublikasiTableModel {
    public static void main(String[] args) {
    ArrayList<Publikasi> test1 = new ArrayList<Publikasi>();
    Buku test11= new Buku();
    try {
        test11.setIdkoleksi("1234567890");
        test11.setJudul("Pemrograman Java");
    } catch (Exception ex) {
        Logger.getLogger(TestPublikasiTableModel.class.getName()).log(Level.SEVERE, null,
        ex);
    }
    
    Buku test12= new Buku();
    
    try {
        test12.setIdkoleksi("1234567891");
        test12.setJudul("Struktur Data");
    } catch (Exception ex) {
        Logger.getLogger(TestPublikasiTableModel.class.getName()).log(Level.SEVERE, null,
        ex);
    }
    
    test1.add(test11);
    test1.add(test12);
    
    Perpustakaan.tambahTabelPublikasi(test11);
    Perpustakaan.tambahTabelPublikasi(test12);
    
    String jdbcUrl = "jdbc:oracle:thin:@172.23.9.185:1521:orcl";
    String userid = "MHS115314034"; // gantikan dengan username anda
    String password = "MHS115314034"; // gantikan dengan password anda
    Connection conn;
    
    try {
        OracleDataSource ds;
        ds = new OracleDataSource();
        ds.setURL(jdbcUrl);
        conn = ds.getConnection(userid, password);
        Statement statement = conn.createStatement();
        System.out.println("Koneksi is OK");
        String sql = "select * from publikasi";
        ResultSet result= statement.executeQuery(sql);
        while(result.next()==true){
        System.out.println(result.getString(1)+" "+result.getString(2));
        }
    } catch (SQLException e) {
        // perform error handling here
        System.out.println("error :"+ e.getMessage());
        }
    }
}

